{% extends "base.html" %}
{% load i18n %}
{% load static %}
{% load icons %}
{% comment %} {% block title %}{% trans "Secrets" %} - {{ compute.name }}{% endblock %}

{% block style %}
    <link rel="stylesheet" href="{% static 'css/sortable-theme-bootstrap.css' %}" />
{% endblock %}

{% block page_heading %}{{ compute }} - {% trans "Secrets" %}{% endblock page_heading %}

{% block page_heading_extra %}
{% include 'create_secret_block.html' %}
{% endblock page_heading_extra %} {% endcomment %}

{% block content %}
<div class="page-wrapper">
    <!--block content-->
    <div class="page-header d-print-none">
        <div class="container-xl">
            <div class="row g-2 align-items-center">
                <div class="col">
                    <div class="page-pretitle">
                        Secrets
                    </div>
                    <h2 class="page-title">
                        {{ compute.name }}
                    </h2>
                </div>
            </div>
        </div>
    </div>

    <div class="page-body">
        <div class="container-xl">
            <div class="card">
                <div class="card-header">
                    <ul class="nav nav-tabs card-header-tabs">
                        <li class="nav-item">
                        <a class="nav-link" href="{% url 'overview' compute.id %}">
                            <span>{% icon 'dashboard' %}&nbsp;&nbsp;{% trans "Overview" %}</span>
                        </a>
                        </li>
                        <li class="nav-item">
                        <a class="nav-link" href="{% url 'instances' compute.id %}">
                            <span>{% icon 'server' %}&nbsp;&nbsp;{% trans "Instances" %}</span>
                        </a>
                        </li>
                        <li class="nav-item">
                        <a class="nav-link" href="{% url 'storages' compute.id %}">
                            <span>{% icon 'hdd-o' %}&nbsp;&nbsp;{% trans "Storages" %}</span>
                        </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{% url 'networks' compute.id %}">
                                <span>{% icon 'sitemap' %}&nbsp;&nbsp;{% trans "Networks" %}</span>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{% url 'interfaces' compute.id %}">
                                <span>{% icon 'wifi' %}&nbsp;&nbsp;{% trans "Interfaces" %}</span>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{% url 'nwfilters' compute.id %}">
                                <span>{% icon 'filter' %}&nbsp;&nbsp;{% trans "NWFilters" %}</span>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link active" href="#">
                                <span class="text-azure">{% icon 'key' %}&nbsp;&nbsp;{% trans "Secrets" %}</span>
                            </a>
                        </li>
                        <li class="nav-item ms-auto">
                            {% include 'create_secret_block.html' %}
                        </li>
                    </ul>
                </div>

                <div class="card-body">
                    <p class="text-muted">
                        <div class="row">
                            {% if not  secrets_all %}
                                <div class="col-lg-12">
                                    <div class="alert alert-warning shadow-sm">
                                        <i class="fa fa-exclamation-triangle"></i> <strong>{% trans "Warning" %}:</strong> {% trans "Hypervisor doesn't have any Secrets" %}
                                    </div>
                                </div>
                            {% else %}
                                <div class="col-lg-12">
                                    <div class="table-responsive">
                                        <table class="table table-hover sortable-theme-bootstrap" data-sortable>
                                            <thead>
                                            <tr class="active">
                                                <th scope="col">{% trans "UUID" %}</th>
                                                <th scope="col">{% trans "Usage Type" %}</th>
                                                <th scope="col">{% trans "Data" %}</th>
                                                <th scope="col" data-sortable="false" style="width:90px;">{% trans "Action" %}</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            {% for secret in secrets_all %}
                                                <tr>
                                                    <th scope="row">{{ secret.uuid }}</th>
                                                    <td>{{ secret.usageType }}</td>
                                                    <td>{{ secret.usage }}</td>
                                                    <td>
                                                        <form action="" method="post" role="form" aria-label="Delete secret form">{% csrf_token %}
                                                            <input type="hidden" name="uuid" value="{{ secret.uuid }}"/>
                                                            <a data-bs-toggle="modal" href="#editSecret{{ secret.uuid }}" class="btn btn-sm btn-primary" title="{% trans "Edit" %}">
                                                                <span class="fa fa-pencil"></span>
                                                            </a>
                                                            <button type="submit" class="btn btn-sm btn-danger" name="delete" title="{% trans "Delete" %}" onclick="return confirm('{% trans "Are you sure?" %}')">
                                                                <span class="fa fa-trash"></span>
                                                            </button>
                                                        </form>

                                                        <!-- Modal -->
                                                        <div class="modal fade" id="editSecret{{ secret.uuid }}" tabindex="-1" role="dialog"
                                                            aria-labelledby="editSecret" aria-hidden="true">
                                                            <div class="modal-dialog">
                                                                <div class="modal-content">
                                                                    <div class="modal-header">
                                                                        <h5 class="modal-title">{% trans "Set secret value" %}</h5>
                                                                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                                                    </div>
                                                                    <div class="modal-body">
                                                                        <form method="post" role="form" aria-label="Edit secret form">{% csrf_token %}
                                                                            <div class="row">
                                                                                <label class="col-sm-3 col-form-label">{% trans "Value" %}</label>
                                                                                <input type="hidden" name="uuid" value="{{ secret.uuid }}">
                                                                                <div class="col-sm-6">
                                                                                    <input type="text" name="value" class="form-control" value="{{ secret.value }}" maxlength="45" required pattern="[a-zA-Z0-9]$+">
                                                                                </div>
                                                                            </div>
                                                                    </div> <!-- /.modal-content -->
                                                                    <div class="modal-footer">
                                                                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{% trans "Close" %}</button>
                                                                        <button type="submit" class="btn btn-primary" name="set_value">{% trans "Set" %}</button>
                                                                    </div>
                                                                        </form>
                                                                </div> <!-- /.tab-content -->
                                                            </div> <!-- /.modal-dialog -->
                                                        </div> <!-- /.modal -->
                                                    </td>
                                                </tr>
                                            {% endfor %}
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            {% endif %}
                        </div>
                    </p>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
{% block script %}
<script src="{% static "js/sortable.min.js" %}"></script>
{% endblock %}